package com.tanhua.server.interceptor;

import com.tanhua.model.domain.User;

/**
 * threadlocal的工具类
 */
public class UserHolder {

    private static ThreadLocal<User> tl = new ThreadLocal<>();

    //将数据存入tl
    public static void set(User user) {
        tl.set(user);
    }

    //从tl中获取数据
    public static User get() {
        return tl.get();
    }

    //从tl中获取当前用户的id
    public static Long getUserId() {
        return get().getId();
    }

    //从tl中获取当前用户的手机号码
    public static String getMobile() {
        return get().getMobile();
    }
}
